import { ref } from 'vue';
import api from 'axios';
import { uivCatalogType, uivCatalogUrlAPI } from 'src/util/UivBaseConst';
import { cataItem } from 'src/hook/common/useCatalogType';


export function useUivCatalogTbl () {
  const resolutionTypeList = ref<cataItem[]>([]);   //分辨率列表
  const colorTypeList = ref<cataItem[]>([]);   //颜色列表
  const lineStyleTypeList = ref<cataItem[]>([]);//线型列表
  const fontFamilyTypeList = ref<cataItem[]>([]);//字体列表
  const fontWeightTypeList = ref<cataItem[]>([]); //字体粗细度
  const protocolTypeList = ref<cataItem[]>([]);//设备通信协议列表
  const encryptionTypeList = ref<cataItem[]>([]);//设备加密类型列表
  const formulaTypeList = ref<cataItem[]>([]);//变量公式列表
  const propsDataTypeList = ref<cataItem[]>([]);//属性数据类型列表
  const propsFormTypeList = ref<cataItem[]>([]);//属性表单类型列表
  const eventTypeList = ref<cataItem[]>([]);//事件类型列表
  const eventOperationTypeList = ref<cataItem[]>([]);//事件行为类型列表
  const operatorTypeList = ref<cataItem[]>([]);//比较运算类型列表
  const notifyMsgTypeList = ref<cataItem[]>([]);//推送信息类型列表
  const motionTypeList = ref<cataItem[]>([]);//动效类型列表
  const alarmTypeList = ref<cataItem[]>([]);//报警类型列表

  const fieldTypeList = ref<cataItem[]>([]);//行业列表
  const graphTypeList = ref<cataItem[]>([]);//图形分类列表

  const uivProjectList = ref<cataItem[]>([]);//项目列表
  const uivPageList = ref<cataItem[]>([]);//页面列表
  const uivVariableList = ref<cataItem[]>([]);//变量列表
  const uivDeviceList = ref<cataItem[]>([]);//设备列表

  const uivTupleList = ref<cataItem[]>([]);//图元列表

  //路径
  let url = ref('');

  //从后台读取目录
  const getUivCatalog = (catalog: uivCatalogType) => {
    switch (catalog) {
      case uivCatalogType.RESOLUTION_TYPE_CODE:
        url.value = uivCatalogUrlAPI.RESOLUTION_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            resolutionTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.COLOR_TYPE_CODE:
        url.value = uivCatalogUrlAPI.COLOR_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            colorTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.LINE_TYPE_CODE:
        url.value = uivCatalogUrlAPI.LINE_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            lineStyleTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.FONT_TYPE_CODE:
        url.value = uivCatalogUrlAPI.FONT_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            fontFamilyTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.FONT_WEIGHT_TYPE_CODE:
        url.value = uivCatalogUrlAPI.FONT_WEIGHT_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            fontWeightTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.PROTOCOL_TYPE_CODE:
        url.value = uivCatalogUrlAPI.PROTOCOL_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            protocolTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.ENCRYPTION_TYPE_CODE:
        url.value = uivCatalogUrlAPI.ENCRYPTION_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            encryptionTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.FORMULA_TYPE_CODE:
        url.value = uivCatalogUrlAPI.FORMULA_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            formulaTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.PROPS_DATA_TYPE_CODE:
        url.value = uivCatalogUrlAPI.PROPS_DATA_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            propsDataTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.PROPS_FORM_TYPE_CODE:
        url.value = uivCatalogUrlAPI.PROPS_FORM_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            propsFormTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.EVENT_TYPE_CODE:
        url.value = uivCatalogUrlAPI.EVENT_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            eventTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.EVENT_OPERATION_TYPE_CODE:
        url.value = uivCatalogUrlAPI.EVENT_OPERATION_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            eventOperationTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.COMPARE_OPERATOR_TYPE_CODE:
        url.value = uivCatalogUrlAPI.COMPARE_OPERATOR_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            operatorTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.NOTIFY_MSG_TYPE_CODE:
        url.value = uivCatalogUrlAPI.NOTIFY_MSG_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            notifyMsgTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.MOTION_TYPE_CODE:
        url.value = uivCatalogUrlAPI.MOTION_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            motionTypeList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.ALARM_TYPE_CODE:
        url.value = uivCatalogUrlAPI.ALARM_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            alarmTypeList.value = res.data.data;
          }
        })
        break;

      case uivCatalogType.FIELD_TYPE_CODE:
        url.value = uivCatalogUrlAPI.FIELD_TYPE_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            fieldTypeList.value = res.data.data;
          }
        })
        break;

      case uivCatalogType.GRAPH_TYPE_CODE:
        url.value = uivCatalogUrlAPI.GRAPH_TYPE_API;
        api.post(url.value).then((res) => {
          deb
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            graphTypeList.value = res.data.data;
          }
        })
        break;

      case uivCatalogType.PROJECT_LIST_CODE:
        url.value = uivCatalogUrlAPI.PROJECT_LIST_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            uivProjectList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.DEVICE_LIST_CODE:
        url.value = uivCatalogUrlAPI.DEVICE_LIST_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            uivDeviceList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.VARIABLE_LIST_CODE:
        url.value = uivCatalogUrlAPI.VARIABLE_LIST_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            uivVariableList.value = res.data.data;
          }
        })
        break;
      case uivCatalogType.PAGE_LIST_CODE:
        url.value = uivCatalogUrlAPI.PAGE_LIST_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            uivPageList.value = res.data.data;
          }
        })
        break;

      case uivCatalogType.TUPLE_LIST_CODE:
        url.value = uivCatalogUrlAPI.TUPLE_LIST_API;
        api.post(url.value).then((res) => {
          if ((res.data) && (res.data.message === 'Success') && (res.data.data)) {
            uivTupleList.value = res.data.data;
          }
        })
        break;
      default:
        break;
    }
  };


  //释放目录
  const removeUivCatalog = (catalog: uivCatalogType) => {
    switch (catalog) {
      case uivCatalogType.RESOLUTION_TYPE_CODE:
        resolutionTypeList.value.length = 0;
        break;
      case uivCatalogType.COLOR_TYPE_CODE:
        colorTypeList.value.length = 0;
        break;
      case uivCatalogType.LINE_TYPE_CODE:
        lineStyleTypeList.value.length = 0;
        break;
      case uivCatalogType.FONT_TYPE_CODE:
        fontFamilyTypeList.value.length = 0;
        break;
      case uivCatalogType.FONT_WEIGHT_TYPE_CODE:
        fontWeightTypeList.value.length = 0;
        break;
      case uivCatalogType.PROTOCOL_TYPE_CODE:
        protocolTypeList.value.length = 0;
        break;
      case uivCatalogType.ENCRYPTION_TYPE_CODE:
        encryptionTypeList.value.length = 0;
        break;
      case uivCatalogType.FORMULA_TYPE_CODE:
        formulaTypeList.value.length = 0;
        break;
      case uivCatalogType.PROPS_DATA_TYPE_CODE:
        propsDataTypeList.value.length = 0;
        break;
      case uivCatalogType.PROPS_FORM_TYPE_CODE:
        propsFormTypeList.value.length = 0;
        break;
      case uivCatalogType.EVENT_TYPE_CODE:
        eventTypeList.value.length = 0;
        break;
      case uivCatalogType.EVENT_OPERATION_TYPE_CODE:
        eventOperationTypeList.value.length = 0;
        break;
      case uivCatalogType.COMPARE_OPERATOR_TYPE_CODE:
        operatorTypeList.value.length = 0;
        break;
      case uivCatalogType.NOTIFY_MSG_TYPE_CODE:
        notifyMsgTypeList.value.length = 0;
        break;
      case uivCatalogType.MOTION_TYPE_CODE:
        motionTypeList.value.length = 0;
        break;
      case uivCatalogType.ALARM_TYPE_CODE:
        alarmTypeList.value.length = 0;
        break;

      case uivCatalogType.FIELD_TYPE_CODE:
        fieldTypeList.value.length = 0;
        break;
      case uivCatalogType.GRAPH_TYPE_CODE:
        graphTypeList.value.length = 0;
        break;

      case uivCatalogType.PROJECT_LIST_CODE:
        uivProjectList.value.length = 0;
        break;
      case uivCatalogType.PAGE_LIST_CODE:
        uivPageList.value.length = 0;
        break;
      case uivCatalogType.DEVICE_LIST_CODE:
        uivDeviceList.value.length = 0;
        break;
      case uivCatalogType.VARIABLE_LIST_CODE:
        uivVariableList.value.length = 0;
        break;

      case uivCatalogType.TUPLE_LIST_CODE:
        uivTupleList.value.length = 0;
        break;
      default:
        break;
    }
  }

  return {
    resolutionTypeList,
    colorTypeList,
    lineStyleTypeList,
    fontFamilyTypeList,
    fontWeightTypeList,
    protocolTypeList,
    encryptionTypeList,
    formulaTypeList,
    propsDataTypeList,
    propsFormTypeList,
    eventTypeList,
    eventOperationTypeList,
    operatorTypeList,
    notifyMsgTypeList,
    motionTypeList,
    alarmTypeList,

    fieldTypeList,
    graphTypeList,

    uivProjectList,
    uivPageList,
    uivTupleList,
    uivDeviceList,
    uivVariableList,

    getUivCatalog,
    removeUivCatalog
  }
}
